/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jfemtest;

import BounderyPack.BounderyNodePair;
import MathLib.triangulation.SaveStructures.Node;
import MathLib.triangulation.SaveStructures.Triangle;
import MathLib.triangulation.SaveStructures.TriangleL;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author mark_o
 */
public class Main2 {
    public static void main(String[] args) throws FileNotFoundException{
        int N = 1605;
        Scanner sc = new Scanner(System.in);
        double[] res = new double[N];
        for (int i = 0; i < res.length; i++) {
            res[i] = Double.parseDouble(sc.next());
        }
        
        String FilePath = "C:\\Users\\mark_o\\Documents\\NetBeansProjects\\MySimpleFEM\\New Folder\\New Folder\\New Folder\\123\\tmp";
            ArrayList<Triangle> TrList = null;
            ArrayList<Node> NodeList = null;
            //ArrayList<BounderyNodePair> BounNodeList = null;

            Scanner in = new Scanner(new FileInputStream(FilePath+"\\file.1.ele"));
            TrList = new ArrayList<Triangle>();
            int n = in.nextInt();
            in.nextInt();
            in.nextInt();
            for (int i = 0; i < n; i++) {
                in.next();
                //TrList.add(new TriangleQ(Integer.parseInt(in.next()), Integer.parseInt(in.next()), Integer.parseInt(in.next()),Integer.parseInt(in.next()), Integer.parseInt(in.next()), Integer.parseInt(in.next())));
                TrList.add(new TriangleL(Integer.parseInt(in.next()), Integer.parseInt(in.next()), Integer.parseInt(in.next())));
            }
            NodeList = getNodes(FilePath+"\\file.1.node");

            double norma = 0.0;

            for (int i = 0; i < TrList.size(); i++) {
                Triangle triangle = TrList.get(i);
                double h = res[triangle.A()-1]+res[triangle.B()-1]+res[triangle.C()-1];
                norma+=h*ComputeTriangleArea(NodeList.get(triangle.A()-1), NodeList.get(triangle.B()-1), NodeList.get(triangle.C()-1));
            }

            System.out.println("\n\n======================================\n\n"+norma);


    }

    public static ArrayList<Node> getNodes(String FilePath) throws FileNotFoundException{
        Scanner in = new Scanner((new FileInputStream(FilePath)));
            ArrayList<Node> NodeList  = new ArrayList<Node>();
            int n = in.nextInt();
            in.nextInt();
            in.nextInt();
            in.nextInt();
            for (int i = 0; i <n; i++) {
                in.next();
                NodeList.add(new Node( ( Double.parseDouble(in.next()) ), ( Double.parseDouble(in.next()) ) , ( isTrue(Integer.parseInt(in.next())) ) ,i ));
                //System.out.println(NodeList.get(i).x+"\t"+NodeList.get(i).y);
            }
            return NodeList;
    }


    public static double ComputeTriangleArea(Node A,Node B,Node C){

        double a =Math.sqrt( (A.x - B.x)*(A.x - B.x) + (A.y - B.y)*(A.y - B.y) );   //a-b
        double b =Math.sqrt( (C.x - B.x)*(C.x - B.x) + (C.y - B.y)*(C.y - B.y) );
        double c =Math.sqrt( (A.x - C.x)*(A.x - C.x) + (A.y - C.y)*(A.y - C.y) );
        double p = (a+b+c)/2.0;
        return Math.sqrt( p*(p-a)*(p-b)*(p-c) );
    }

    private static boolean isTrue(int s){
        if(s==0){return false;}else{return true;}
    }

    public static ArrayList<Node>  generateBoundsNode(ArrayList<Node> NodeList){
        ArrayList<Node> BoundsNodeList = new ArrayList<Node>();
        //BoundsNodePosList = new ArrayList<Integer>();
        if(NodeList==null){return null;}
        for(int i =0;i<NodeList.size();i++){
            Node tmp = NodeList.get(i);
            if(tmp.IsOnBoundery){
                BoundsNodeList.add(new Node(tmp.x, tmp.y, true,tmp.Number));
            }
        }
        return  BoundsNodeList;
    }

    public static ArrayList<BounderyNodePair> get(String FilePath,ArrayList<Node> NodeList) throws FileNotFoundException{
        Scanner in = new Scanner((new FileInputStream(FilePath)));
            ArrayList<BounderyNodePair> BounNodeList  = new ArrayList<BounderyNodePair>();
            in.nextInt();
            in.nextInt();
            in.nextInt();
            in.nextInt();
            int n = in.nextInt();
            in.nextInt();
            for (int i = 0; i <n; i++) {
                in.nextInt();
                int A = in.nextInt();
                int B = in.nextInt();

                BounNodeList.add(new BounderyNodePair(NodeList.get(A-1), NodeList.get(B-1)));
                in.nextInt();
            }
            return BounNodeList;
    }

    public static void get(String FilePath,ArrayList<Integer> NodeList1,ArrayList<Integer> NodeList2) throws FileNotFoundException{
        Scanner in = new Scanner((new FileInputStream(FilePath)));
            in.nextInt();
            in.nextInt();
            in.nextInt();
            in.nextInt();
            int n = in.nextInt();
            in.nextInt();
            for (int i = 0; i <n; i++) {
                in.nextInt();
                NodeList1.add(in.nextInt());
                NodeList2.add(in.nextInt());
                in.nextInt();
            }
    }





}
